<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GCC 4.4 Release Series &mdash; Porting to the New Tools</title>
<link rel="stylesheet" type="text/css" href="https://gcc.gnu.org/gcc.css" />
</head>

<body>
<h1>GCC 4.4 Release Series<br />Porting to the New Tools</h1>

<p>
The GCC 4.4 release series differs from previous GCC releases in more
than the usual list of <a href="changes.html">new
features</a>. Some of these changes are a result of bug fixing, and
some old behaviors have been intentionally changed in order to support
new standards, or relaxed in standards-conforming ways to facilitate
compilation or runtime performance. Some of these changes are not
visible to the naked eye, and will not cause problems when updating
from older GCC versions.
</p>

<p>
However, some of these changes are visible, and can cause grief to
users porting to GCC 4.4. This document is an effort to identify major
issues and provide clear solutions in a quick and easily-searched
manner. Additions and suggestions for improvement are welcome.
</p>

<h2>C language issues</h2>

<h3>Preprocessor conditionals always evaluated</h3>

<p>
When using the preprocessor statement #elif, the argument is now
evaluated even if earlier #if or #elif conditionals evaluated
non-zero.  This is done to make sure they are valid constant
expressions. (For details, see
bug <a href="https://gcc.gnu.org/PR36320">36320</a>).
</p>

<p>
For example, the code
</p>

<pre>
#if 1
#elif
#endif
</pre>

<p>
Now produces the following diagnostic:
</p>

<pre>
error: #elif with no expression
</pre>

<p>
 To fix this, either use #else without an argument or provide a
 constant expression when using #elif.
</p>


<h3>Stricter aliasing requirements</h3>

<p>
GCC warns about more cases of type-punning while optimizing, like the
following.
</p>

<pre>
struct A 
{ 
  char data[14];
  int i; 
};

void foo()
{
  char buf[sizeof(struct A)];
  ((struct A*)buf)-&gt;i = 4;
}
</pre>

<p>
Now produces the following diagnostic:
</p>

<pre>
warning: dereferencing type-punned pointer will break strict-aliasing rules
</pre>

<p>
This can be temporarily worked around by
using <code>-fno-strict-aliasing </code> or by ignoring this class of
warning via <code>-Wno-strict-aliasing</code>. To fix, access the
structure from pointers of an equivalent type, use a union, use
memcpy, or (if using C++) use placement <code>new</code>. 
See the section <a href="../bugs/#casting_and_optimization"> 
Casting does not work as expected when optimization is turned on</a>
in our bug reporting documentation for more information.
</p>

<h2>C++ language issues</h2>

<h3>Header dependency changes</h3>

<p>
Some of the standard C++ library include files have been edited to
include only the smallest possible number of additional files. As such,
C++ programs that used <code>std::printf</code> without including
&lt;cstdio&gt;, or used <code>uint32_t</code> without including
&lt;stdint.h&gt; will no longer compile.
</p>

<p>
In detail:
</p>

<p>
The file &lt;cstdio&gt; is no longer included as part of
&lt;string&gt;, &lt;ios&gt;, &lt;iomanip&gt;, &lt;streambuf&gt;, or
&lt;locale&gt;. 
</p>

<p>
The file &lt;stdint.h&gt; is no longer included as part of
&lt;string&gt; or&lt;ios&gt;.
</p>

<h3>Strict null-terminated sequence utilities</h3>

<p>
Some of the standard C++ library include files have been edited to use
replacement overloads for some common C library functions (if
available), with the goal of improving const-correctness: functions
passed a <code>const char*</code> return <code>const char*</code>.
</p>

<p>
The table below shows the functions and files that have been changed.
</p>

<table class="border">
  <tr>
    <th>Header</th>
    <th>Functions</th>
  </tr>
  <tr>
    <td>&lt;cstring&gt;</td>
    <td>
      <code>strchr</code>,
      <code>strpbrk</code>,
      <code>strrchr</code>,
      <code>strstr</code>,
      <code>memchr</code>
    </td>
  </tr>
  <tr>
    <td>&lt;cwchar&gt;</td>
    <td>
      <code>wcschr</code>
      <code>wcspbrk</code>,
      <code>wcsrchr</code>,
      <code>wcsstr</code>,
      <code>wmemchr</code>
    </td>
  </tr>
</table>

<p>An example.</p>

<pre>
#include &lt;cstring&gt;

const char* str1;
char* str2 = strchr(str1, 'a');
</pre>

<p>
Gives the following compiler error:
</p>

<pre>
error: invalid conversion from ‘const char*’ to ‘char*’
</pre>

<p>Fixing this is easy, as demonstrated below.
</p>
<pre>
#include &lt;cstring&gt;

const char* str1;
const char* str2 = strchr(str1, 'a');
</pre>

<p>
More information about the C++ standard requirements can be found in
chapter 21, section "Null-terminated sequence utilities."
</p>

<h3>Initialization changes</h3>

<p>
GCC by default no longer accepts code such as
</p>
<pre>
struct A { virtual ~A (); };

struct B : public A { int i; };

struct C
{ 
  const B a; 
  C() { bar(&amp;a); } 
  void bar(const B*); 
};
</pre>

<p>
but will issue the diagnostic
</p>

<pre>
In constructor 'C::C()':
error: uninitialized member 'C::a' with 'const' type 'const B'
</pre>

<p>To fix, use a member initialization list to initialize the member, like so:
</p>

<pre>
C(): a(B()) { bar(&amp;a); } 
</pre>

<h2>Links</h2>

<p>
Jakub Jelinek, <a href="https://listman.redhat.com/archives/fedora-devel-list/2009-February/msg00180.html">Results of a test mass rebuild of rawhide-20090126 with gcc-4.4.0-0.9</a>
</p>

</body>
</html>
